package com.seveneight.baijiesteward.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.seveneight.baijiesteward.R;
import com.seveneight.baijiesteward.base.TeamBean;
import com.seveneight.baijiesteward.http.HttpConfig;
import com.seveneight.baijiesteward.ui.user.activity.TeamInfoActivity;
import com.seveneight.baijiesteward.utils.DateUtil;
import com.seveneight.baijiesteward.utils.GlideLoader;
import com.seveneight.baijiesteward.utils.StringFormat;
import com.seveneight.baijiesteward.utils.StringUtils;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by user1 on 2018/4/4.
 */

public class TeamAdapter extends ListBaseAdapter<TeamBean> {

    int type=1;
    public TeamAdapter(Context context,int type) {
        super(context);
        this.type=type;
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_team;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        CircleImageView ci_head = holder.getView(R.id.ci_head);
        TextView tv_name = holder.getView(R.id.tv_name);
        TextView tv_date = holder.getView(R.id.tv_date);
        TextView tv_type = holder.getView(R.id.tv_type);
        TeamBean teamBean = mDataList.get(position);
        if (TextUtils.isEmpty(teamBean.getHeadImgUrl())) {
            GlideLoader.displayImg(mContext, R.mipmap.user_head, ci_head);
        } else {
            GlideLoader.displayImg(mContext, HttpConfig.SOURCE_URL + teamBean.getHeadImgUrl(), ci_head);
        }
        tv_name.setText(teamBean.getRealName());
        tv_type.setText(teamBean.getRankName());
        tv_date.setText(DateUtil.formatDate(teamBean.getRegisterTime()));
        if (!StringUtils.isEmpty(teamBean.getRankName())){
            if (teamBean.getRankName().equals("试用")){
                tv_type.setTextColor(Color.parseColor("#999999"));
            }else {
                tv_type.setTextColor(Color.parseColor("#4E6ECE"));
            }
        }
        holder.getView(R.id.item_team_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, TeamInfoActivity.class);
                intent.putExtra("data",teamBean);
                intent.putExtra("type",type);
                mContext.startActivity(intent);
            }
        });
    }
}
